﻿using MediatR;
using Production_Get.API.DTO;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.Produce.ManifestInfos;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.MaterialManagement.Select
{
    public class SpecScretenHandler : IRequestHandler<SpecScretenComm, Result>
    {
        private readonly IBaseRepositoryGet<MaterialSpecs> MaterialSpecsRepository;
        public SpecScretenHandler(IBaseRepositoryGet<MaterialSpecs> materialSpecsRepository)
        {
            MaterialSpecsRepository = materialSpecsRepository;
        }

        public async Task<Result> Handle(SpecScretenComm request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };

            string sql = "SELECT * FROM MaterialSpecs Where ChooseId="+request.ChooseId;
            var list = MaterialSpecsRepository.GetAll(sql).FirstOrDefault();
            if (list != null)
            {
                result.Code = (int)CommonErrorCodes.Success;
                result.Data = list;
                result.Msg = "显示成功";
            }
            else
            {
                result.Msg = "显示失败";
            }
            return result;
        }
    }
}
